<?php

namespace App\Models\Scm;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Location extends Model
{
    use HasFactory;
    public $timestamps = FALSE;
    protected $table = 'biz_location';
    protected $fillable = ['id', 'create_by', 'create_time', 'update_by', 'update_time', 'location_name', 'location_code', 'warehouse_id', 'status', 'del_flag', 'kingdee_id'];

    public function __construct(array $attributes = [])
    {
        parent::__construct($attributes);
    }

    public function insertOne($params){
        return self::create($params);
    }

    public function insertMany($params){
        return self::insert($params);
    }

    public function updateById($params, $id){
        return self::where("id", $id)->update($params);
    }

    public function findRowById($id){
        return self::whereRaw('BINARY id = ?', [$id])->first();
    }

    public function findRowByCode($location_code){
        return self::where('location_code', $location_code)->first();
    }

    public function findRowIfExist($code, $name){
        return self::where('location_name', $name)->where('location_code', $code)->first();
    }

}
